package com.scs.application.modules.sys.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.annotation.TableName;
import com.scs.application.core.entity.DataEntity;
import com.scs.application.modules.upgrade.db.annotation.EntityClassAnnotation;
import com.scs.application.modules.upgrade.db.annotation.EntityFieldAnnotation;
import com.scs.application.modules.upgrade.db.annotation.EntityIndexAnnotation;
import com.scs.application.modules.upgrade.db.enums.EntityFieldType;
import lombok.Data;
import lombok.experimental.Accessors;

import java.util.Map;

/**
 * <p>
 *
 * </p>
 */
@Data
@Accessors(chain = true)
@EntityClassAnnotation(remark = "系统日志表")
@TableName("sys_log")
@EntityIndexAnnotation(ix = {"bus_type","log_type","gmt_create","bus_id","bus_key"})
public class Log extends DataEntity {


    // id ,在父类中处理

    @EntityFieldAnnotation(
            text = "",
            length = "255",
            not_null = false,
            default_value = "",
            comment = ""
    )
    private String busType;

    @EntityFieldAnnotation(
            text = "业务单号",
            length = "50",
            not_null = false,
            default_value = "",
            comment = ""
    )
    private String busKey;

    @EntityFieldAnnotation(
            text = "业务ID",
            type = EntityFieldType.LONG,
            length = "",
            not_null = false,
            default_value = "",
            comment = ""
    )
    private String busId;

    @EntityFieldAnnotation(
            text = "业务表",
            length = "50",
            not_null = false,
            default_value = "",
            comment = ""
    )
    private String busTable;

    @EntityFieldAnnotation(
            text = "",
            length = "20",
            not_null = false,
            default_value = "",
            comment = ""
    )
    private String logType;

    @EntityFieldAnnotation(
            text = "操作IP",
            length = "30",
            not_null = false,
            default_value = "",
            comment = "操作IP"
    )
    private String ip;


    // gmt_create ,在父类中处理

    @EntityFieldAnnotation(
            text = "",
            length = "1100",
            not_null = false,
            default_value = "",
            comment = ""
    )
    private String creatorName;

    @EntityFieldAnnotation(
            text = "返回信息",
            type = EntityFieldType.LONGTEXT,
            not_null = false,
            default_value = "",
            comment = ""
    )
    private String msg;

    @EntityFieldAnnotation(
            text = "参数",
            type = EntityFieldType.LONGTEXT,
            not_null = false,
            default_value = "",
            comment = "参数"
    )
    private String param;

    /**
     * 方式说明:获取对象实例
     *         log.setBusType(BusType.FSDType.type01);
     *         log.setCreatorName("system");
     *         log.setLogType(LogType.success);
     *         log.setParam(JSON.toJSONString(queryContext));
     */
    public static Log getLog(String busType, String logType, String creatorName, Map<String, String> param) {
        Log log=new Log();
        log.setBusType(busType);
        log.setCreatorName(creatorName);
        log.setLogType(logType);
        if(param != null) log.setParam(JSON.toJSONString(param));
        return log;
    }

    /**
     * 方式说明:获取对象实例
     *         log.setBusType(BusType.FSDType.type01);
     *         log.setCreatorName("system");
     *         log.setLogType(LogType.success);
     *         log.setParam(JSON.toJSONString(queryContext));
     */
    public static Log getLog(String busType, String logType, String creatorName, JSONObject param) {
        Log log=new Log();
        log.setBusType(busType);
        log.setCreatorName(creatorName);
        log.setLogType(logType);
        if(param != null) log.setParam(JSON.toJSONString(param));
        return log;
    }


    /**
     * 方式说明:获取对象实例
     *         log.setBusType(BusType.FSDType.type01);
     *         log.setCreatorName("system");
     *         log.setLogType(LogType.success);
     *         log.setParam(JSON.toJSONString(queryContext));
     */
    public static Log getLog(String busType, String logType, String creatorName, String param) {
        Log log=new Log();
        log.setBusType(busType);
        log.setCreatorName(creatorName);
        log.setLogType(logType);
        log.setParam(param);
        return log;
    }

    /**
     * 方式说明:获取对象实例
     *         log.setBusType(BusType.FSDType.type01);
     *         log.setCreatorName("system");
     *         log.setLogType(LogType.success);
     *         log.setParam(JSON.toJSONString(queryContext));
     */
    public Log  setLog(String logType,  String msg) {
        this.setLogType(logType);
        this.setMsg(msg);
        return this;
    }

}
